﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using AvaloniaApplication1.Models;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;


namespace AvaloniaApplication1.ViewModels
{
    public class SignPropertyViewModel : ReactiveObject
    {
        public SignPropertyViewModel()
        {

        }

        [Reactive] public SignIcon SignIcon { get; set; } = SignIcon.Error;

        private string m_SignName = "测试签名者Tom";

        /// <summary>
        /// 签名者
        /// </summary>
        public string SignName
        {
            get => m_SignName;
            set
            {
                if (m_SignName == value)
                {
                    return;
                }
                m_SignName = value;
                this.RaisePropertyChanged(nameof(TimeSpanContent));
            }
        }

        private string m_Company = "测试单位Mesign";

        public string Company
        {
            get => m_Company;
            set
            {
                if (m_Company != value)
                {
                    return;
                }

                m_Company = value;
                this.RaisePropertyChanged(nameof(CertificateLevelContent));
            }
        }

        private DateTime m_SignTime = DateTime.Now;

        public DateTime SignTime
        {
            get => m_SignTime;
            set
            {
                if (m_SignTime == value)
                {
                    return;
                }

                m_SignTime = value;
                this.RaisePropertyChanged(nameof(TimeSpanContent));
            }
        }

        /// <summary>
        /// 签名算法
        /// </summary>
        public string SignAlgorithm = "TestSignAlgorithm";

        /// <summary>
        /// 原因
        /// </summary>
        public string Reason = "TestReason";

        /// <summary>
        /// 位置
        /// </summary>
        public string Location { get; set; } = "TestLocation";

        /// <summary>
        /// 是否签名有效
        /// </summary>
        public bool IsSignEffective = true;

        /// <summary>
        /// 签名者的身份是否可信
        /// </summary>
        public bool IsCredibleSigner = true;

        /// <summary>
        /// 是否启用LTV
        /// </summary>
        public bool IsUseLTV = true;

        /// <summary>
        /// 签名证书
        /// </summary>
        public Byte[] SignBytes;

        /// <summary>
        /// 时间戳证书
        /// </summary>
        public Byte[] TimeSpanBytes;

        /// <summary>
        /// 签名信息
        /// </summary>
        [Reactive] public string SignInfo { get; set; } = "";

        /// <summary>
        /// 有效性小结
        /// </summary>
        [Reactive] public string EffctiveInfo { get; set; } = "";

        /// <summary>
        /// 签名者信息
        /// </summary>
        [Reactive] public string SignerInfo { get; set; } = "ces";

        /// <summary>
        /// 时间戳显示内容
        /// </summary>
        public string TimeSpanContent
        {
            get
            {
                StringBuilder sbResult = new StringBuilder(50);
                sbResult.AppendLine($"时间戳有效, 由{m_SignName}签名");
                string time = SignTime.ToString("yyyy-MM-dd HH:mm:ss").TrimEnd();
                //sbResult.AppendLine($"{AppResource.时间戳时间}:123{AppResource.此时间来源于受信任的时间戳防伪造防篡改不可抵赖}");
                sbResult.AppendLine($"时间戳时间：{SignTime.ToString("yyyy-MM-dd HH:mm:ss")}\u0020此时间来源于受信任的时间戳防伪造防篡改不可抵赖");
                //sbResult.AppendLine($"{AppResource.时间戳时间}:,此时间来源于受信任的时间戳,防伪造,防篡改,不可抵赖,此时间来源于受信任的时间戳,防伪造,防篡改,不可抵赖");
                sbResult.AppendLine();
                return sbResult.ToString();
            }
        }

        /// <summary>
        /// 证书级别
        /// </summary>
        public string CertificateLevelContent
        {
            get
            {
                return $"签名者{SignName}单位{Company} 身份真实可信";
            }
        }


    }
}
